/*
Copyright SecureKey Technologies Inc. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/
package ichain

import (
	reqContext "context"
	"time"

	"git.cloud.inspur.com/ichain/ichain-protos-go/common"
	"git.cloud.inspur.com/ichain/ichain-sdk-go/pkg/common/options"
	"github.com/golang/protobuf/proto"
)

// ChainService 链服务抽象接口，具备获取链配置，链事件服务，链成员
type ChainService interface {
	ConfigService() (ChainConfigService, error)
	EventService(opts ...options.Opt) (EventService, error)
	Membership() (ChainMembership, error)
	ChainConfig() (ChainCfg, error)
	Transactor(reqCtx reqContext.Context) (Transactor, error)
	Discovery() (DiscoveryService, error)
}

// Transactor  创建/发送交易提案，创建发送交易
type Transactor interface {
	NewTxHeader() (TransactionHeader, error)
	CreatePayload(headerType common.HeaderType, opts ChainHeaderOpts, msg proto.Message) (*common.Payload, error)
	Sender
	ProposalSender
}

// ChainProvider 链服务提供者
type ChainProvider interface {
	ChainService(ctx ClientContext, chainID string) (ChainService, error)
}

type ErrorHandler func(ctxt ClientContext, chainID string, err error)

type ChainHeaderOpts struct {
	TxnHeader   TransactionHeader
	Epoch       uint64
	ContractID  string
	Timestamp   time.Time
	TLSCertHash []byte
}
